package com.example.demo.controller;

import com.example.demo.pojo.Result;
import com.example.demo.pojo.Book;
import com.example.demo.pojo.request.BaseRequest;
import com.example.demo.pojo.request.BookRequest;
import com.example.demo.pojo.request.UserPageRequest;
import com.example.demo.service.IBookService;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@CrossOrigin
@RestController
@RequestMapping("/book")
public class BookControl {
    @Autowired
    private IBookService bookService;
    //查询全部
    @GetMapping("/list")
    public Result list(){
        List<Book> select = bookService.list();
        return Result.success(select);
    }

    //分页查询
    @GetMapping("/page")
    public Result page(BookRequest bookRequest){
        Object page = bookService.page(bookRequest);
        return Result.success(page);
    }

    //添加数据
    @PostMapping("/add")
    public Result add(@RequestBody Book Book){
        bookService.save(Book);
        return Result.success();
    }

    //根据id编辑回写
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Book Book = bookService.getUser(id);
        return Result.success(Book);
    }

    //根据id编辑
    @PutMapping("/update")
    public Result update(@RequestBody Book Book){
        bookService.getIDUser(Book);
        return Result.success();
    }

    //根据id删除
    @DeleteMapping("/del/{id}")
    public Result delete(@PathVariable Integer id){
        bookService.delete(id);
        return Result.success();
    }






}
